<%@ page import = "java.util.*,
                   ro.xblue.translator.LanguageBean,
                   ro.gateway.aida.servlet.*,
                   ro.gateway.aida.obj.*,
                    ro.gateway.aida.obj.searchrows.*,
ro.gateway.aida.obj.db.SearchDB,
                   ro.gateway.aida.srv.*,
                   ro.gateway.aida.*,
                   java.sql.SQLException,
                   ro.xblue.translator.TranslatorConstants,
                   ro.gateway.aida.utils.LocalisedSortableList,
                   ro.xblue.translator.TranslatorUtils" %>

<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="gtw" %>
<%@ taglib uri="/WEB-INF/usr.tld" prefix="usr" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> 
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>

<%
String ctx = request.getContextPath();
Hashtable bean = (Hashtable) request.getAttribute(SearchActivitiesServlet.PNAME_BEAN);
    if (bean == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
String key = (String) bean.get(SearchActivitiesServlet.PNAME_KEY);
LanguageBean lang_bean = TranslatorUtils.getCurrentLanguage(request, application);
String lang=lang_bean.language;

//get search lists:
Object screen= request.getAttribute(SearchActivitiesServlet.PNAME_SCREEN);
LocalisedSortableList orgs=(LocalisedSortableList)bean.get(SearchActivitiesServlet.PNAME_ORGS);
Vector perss=(Vector)bean.get(SearchActivitiesServlet.PNAME_PERSS);
Vector sectors=(Vector)bean.get(SearchActivitiesServlet.PNAME_SECTORS);
Vector countries=(Vector)bean.get(SearchActivitiesServlet.PNAME_COUNTRIES);
List results=(List)session.getAttribute("prjPageSearchResults");
ActivityStatus [] statuses=(ActivityStatus[])bean.get(SearchActivitiesServlet.PNAME_STATUS);
%>

<html>
<head>
	<link rel="shortcut icon" href=<html:rewrite page="/images/lpd.png"/> type="image/ico" />	
	
    <title>Local Projects Database - Search</title>
<link rel="stylesheet" href="../alf.css" type="text/css">
</head>
<jsp:include page="../header.jsp" />

<trans:initPage module="prj_pages" />
<!--END HEADER-->

<!-- Search FORM -->
<% if (SearchActivitiesServlet.PV_SCR_ERROR.equals(screen)) { %>
<div align=center class="text_searchbold">
<b>
<trans:showPageMessage label="asearch.plsselatleastonesrchcrit" />
<br>
<a href="<%=ctx%>/activity/search">Back</a>
</b>
</div>
<% } else if (results==null) { %>
<table align="center" width="90%" cellspacing="1" cellpadding="4" border="0" background=<html:rewrite page="/images/pixelbgtable.gif"/> class="text_searchbold">
  <form name="searchform" method="post" action="<%=ctx%>/activity/search">
    <input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />
    <input type="hidden" name="lang" value="<%=lang%>" />
    <input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_SAVE%>" />
    <!-- Location Search -->
    <tr>
      <td colspan=2 align=center class="textalb"><trans:showPageMessage label="asearch.asearch" />
    <tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.country" />:</td>
	  <td class="text_searchbold"><select name="country">
          <option value=""><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Enumeration e = countries.elements() ; e.hasMoreElements() ;) {
Country c=(Country)e.nextElement();
%>
          <option value="<%=c.getIso3()%>"><%=c.getName()%></option>
          <% } %>
        </select></td>
        
      <tr bgcolor="ffffff">
      <!-- Sector Search -->
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.sectors" />:</td>
	  <td class="text_searchbold">
        <select name="sector">
          <option value="-1"><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Enumeration e = sectors.elements() ; e.hasMoreElements() ;) {
AIDASector sec=(AIDASector)e.nextElement();
%>
          <option value="<%=sec.getRo_aida_code()%>"><%=sec.getTitle()%></option>
          <% } %>
        </select>
      </td>
    </tr>
    <!-- Funding search -->
    <tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.fundingorgs" />:</td>
	  <td class="text_searchbold">
        <select name="funorg">
          <option value="-1"><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Iterator e = orgs.iterator() ; e.hasNext() ;) {
Organization org=(Organization)e.next();
org.getName().setMaxViewLength(60);

%>
          <option value="<%=org.getId()%>"><%=org.getName().getString(lang)%></option>
          <% } %>
        </select>
      </td><tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.involvedpersons" />:</td>
	  <td class="text_searchbold">
        <select name="pers">
          <option value="-1"><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Enumeration e = perss.elements() ; e.hasMoreElements() ;) {
Person pers=(Person)e.nextElement();

%>
          <option value="<%=pers.getId()%>"><%=pers.getName()%></option>
          <% } %>
        </select>
      </td>
    </tr>
    <!-- Contracting Institutions search -->
    <tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.contractinginstit" />:</td>
	  <td class="text_searchbold">
        <select name="conorg">
          <option value="-1"><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Iterator e = orgs.iterator() ; e.hasNext() ;) {
Organization org=(Organization)e.next();
org.getName().setMaxViewLength(60);
%>
          <option value="<%=org.getId()%>"><%=org.getName().getString(lang)%></option>
          <% } %>
        </select>
      </td>

    </tr>
    <!-- Beneficiars search -->
    <tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.benorgs" />:</td>
	  <td class="text_searchbold">
        <select name="benorg">
          <option value="-1"><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Iterator e = orgs.iterator() ; e.hasNext() ;) {
Organization org=(Organization)e.next();
org.getName().setMaxViewLength(60);

%>
          <option value="<%=org.getId()%>"><%=org.getName().getString(lang)%></option>
          <% } %>
        </select>
      </td>
    </tr>
    <!-- Donor Organization Search -->
    <tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.donororg" />:</td>
	  <td class="text_searchbold">
        <select name="donorg">
          <option value="-1"><trans:showPageMessage label="asearch.all" hide_link="true" /></option>
          <%
for (Iterator e = orgs.iterator() ; e.hasNext() ;) {
Organization org=(Organization)e.next();
org.getName().setMaxViewLength(60);

%>
          <option value="<%=org.getId()%>"><%=org.getName().getString(lang)%></option>
          <% } %>
        </select>
      </td><tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.donorprjid" />:</td>
	  <td class="text_searchbold">
        <input type="text" name="projid">
      </td>
    </tr>
    <tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.prjtitle" />:</td>
	  <td class="text_searchbold">
        <input type="text" name="title">
      </td><tr bgcolor="ffffff">
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.descobjresults" />:</td>
	  <td class="text_searchbold">
        <input type="text" name="desc">
      </td>
    </tr>
    <tr bgcolor="ffffff">
      <!-- Project Status Search -->
      <td class="text_searchbold"> <trans:showPageMessage label="asearch.projstatus" />:</td>
	  <td class="text_searchbold">
        <select name="status">
          <option value="-1"><trans:showPageMessage label="asearch.selstatus" hide_link="true" /></option>
          <% for (int i = 0; i < statuses.length; i++) { %>
          <option value="<%=statuses[i].getId()%>"><%=statuses[i].getStatus(lang_bean.language)%></option>
          <% } %>
        </select>
    <tr bgcolor="#f9f9f9">
      <td colspan="2">
        <div align="center">
          <input type=submit name="sbutton" value="<trans:showPageMessage label="asearch.search" hide_link="true" />" class="butonsave">
        </div>
      </td>
    </tr>
  </form>
</table><trans:showPageMessage label="translator.showhiddentags"/>

<!-- Results DISPLAY -->
<% } else if (results!=null) {
 Calendar cals = Calendar.getInstance();
 Calendar cale = Calendar.getInstance();

 %>

<table width="90%" align="center" cellpadding="5" cellspacing="1" border="0" background=<html:rewrite page="/images/pixelbgtable.gif"/>>
  <tr>
    <td colspan=3 class="textalb">
      <div align=center><trans:showPageMessage label="asearch.searchres" />
            <%if (results.size()==0) { %>
              :<trans:showPageMessage label="asearch.noprojfoundtryanothersearch" /></div>
              </td>
			  </tr>
			 <%} else {%>
</div>            
</td>
</tr>

  <tr bgcolor="#FFFFFF">
    <th class="text_searchbold"> 
		    <a href=<%=ctx%>/activity/search?mode=titleSort>
    <trans:showPageMessage label="asearch.prjtitle" /></a>
    </th>
    <td class="text_searchbold"> 
		    <a href=<%=ctx%>/activity/search?mode=countrySort>
    <trans:showPageMessage label="asearch.country" /> 
    </a>
    </th>
    <td class="text_searchbold"> 
    <a href=<%=ctx%>/activity/search?mode=sectorSort>
    <trans:showPageMessage label="asearch.sector" /> 
    </a>
    </td>
    <%Iterator i=results.iterator();
while (i.hasNext()) {

ActivityRow ar=(ActivityRow)i.next();
%>
  <tr bgcolor="#FFFFFF">
    <td class="text_search"> <a href="<%=ctx%>/activity/view.jsp?id=<%=ar.getId()%>"><%=ar.getTitle()%></a>
    </td>
  <td class="text_search">
  <%=ar.getCountry()%>
    </td>
    <td class="text_search">
  <%=ar.getSector()%>
    </td>
  </tr>
  <%} %>
  <tr>
</tr>
<% } %>
<tr>
<logic:present name="pagetk">
<td colspan=3 bgcolor="#FFFFFF" align="center">
<trans:showPageMessage label="asearch.pages" /> 
<logic:iterate scope="request" name="pagetk" id="token">
<html:link page="/activity/search" name="token" property="params" styleClass="text_search">
<bean:write name="token" property="no"/>
</html:link>
&nbsp;|&nbsp;
</logic:iterate>
</td>
</tr>
</logic:present>
<trans:showPageMessage label="translator.showhiddentags"/>
<tr>
    <td bgcolor="#f9f9f9" colspan=3 class="text_searchbold"> <img src="<%=ctx%>/images/arrow_blue.gif" hspace=4>
    <input type=button class=buton 
    onclick="javascript:window.location.href='<%=ctx%>/activity/search?mode=newsearch';"
    value="<trans:showPageMessage label="asearch.perfanothersearch" hide_link="true" />" />

    <input type=button class=buton 
    onclick="javascript:window.location.href='<%=ctx%>/activity/search?excel=yes';" value="<trans:showPageMessage label="asearch.exporttocvs" hide_link="true" />" />
      
	  </td>
  </tr>
</table>
<% } %><trans:showPageMessage label="translator.showhiddentags"/>
<!--START BOTTOM-->


<jsp:include page="../footer.jsp" />